<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta name="viewport"
		  content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
	<meta http-equiv="X-UA-Compatible" content="ie=edge">
	<title>Document</title>
	<link rel="stylesheet" href="./temp/layui/css/layui.css">
	<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
	<script src="./temp/layui/layui.js"></script>
</head>
<body>
<form class="layui-form layui-form-pane" action="" style="margin-top: 8%;margin-left: 33%">
	<div class="layui-form-item">
		<label class="layui-form-label">用户名</label>
		<div class="layui-input-inline">
			<input type="text" name="username" required lay-verify="required" placeholder="请输入您的用户名" autocomplete="off" class="layui-input" value="xiaoxin">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">手机</label>
		<div class="layui-input-inline">
			<input type="text" name="phone" required lay-verify="phone" placeholder="请输入您的手机号码" autocomplete="off" class="layui-input" value="15674869541">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">邮箱</label>
		<div class="layui-input-inline">
			<input type="email" name="email" required lay-verify="email" placeholder="请输入您的邮箱" autocomplete="off" class="layui-input" value="147@qq.com">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">验证码</label>
		<div class="layui-input-inline">
			<input type="text" name="captcha" required lay-verify="required" placeholder="请输入验证码" autocomplete="off" class="layui-input" value="asd">
		</div>
		<img src="./callCaptcha.php" id="code" style="height: 40px;" alt="验证码">
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">密码</label>
		<div class="layui-input-inline">
			<input type="password" name="password" required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input" value="123123123">
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">确认密码</label>
		<div class="layui-input-inline">
			<input type="password" name="repassword" required lay-verify="required" placeholder="请确认密码" autocomplete="off" class="layui-input" value="123123123">
		</div>
		<div class="layui-form-mid layui-word-aux">辅助文字</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block">
			<button class="layui-btn" lay-submit lay-filter="reg">立即注册</button>
		</div>
	</div>
</form>

<script>
    $('#code').click(function () {
        $(this).attr('src',$(this).attr('src')+'?'+Math.random())
    })
    //Demo
    layui.use('form', function(){
        var form = layui.form;
        //监听提交
        form.on('submit(reg)', function(data){
            $.post("./addUser.php", data.field, function(res) {
                if (res.code==0){
                    layer.alert(res.msg, {icon: 6},function () {
						location.href='./login.php';
                    });
                }else{
                    $('#code').click();
                    layer.msg(res.msg, {icon: 9},function () {
                    });
                }
            },'json');
            return false;
        });
    });
</script>
</body>
</html>